<template>
  <!-- 这里总是报错 -->
  <div class="full-screen-container">
    <div class="form-container">
      <!-- <el-form ref="userForm" :model="userForm" label-width="100px" class="user-form"> -->
        <!-- 很小一个地方就会影响到全局 真的不能相信 ai 纯纯乱改 -->
      <el-form :model="userForm" label-width="100px" class="user-form">
        <el-form-item value="用户名">
          <el-input v-model="userForm.userName" placeholder="请输入用户名"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input type="password" v-model="userForm.password" placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item label="性别">  
          <!-- 假设使用单选按钮组件 -->  
          <el-radio-group v-model="userForm.gender">  
            <el-radio label="男">男</el-radio>  
            <el-radio label="女">女</el-radio>  
          </el-radio-group>  
        </el-form-item>  
        <el-form-item label="出生日期">  
          <!-- 假设使用日期选择器组件 -->  
          <el-date-picker  
            v-model="userForm.birthDate"  
            type="date"  
            placeholder="选择日期">  
          </el-date-picker>  
        </el-form-item> 
        <el-form-item>
          <el-button type="primary" @click="submitForm">提交</el-button>
          <el-button @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>


<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { ElMessage, ElForm, ElFormItem, ElInput, ElButton, ElRadioGroup, ElRadio, ElDatePicker } from 'element-plus';
import axios from 'axios';
import { defineComponent } from 'vue';
defineComponent({
  name: 'UserRegister'
});


const userForm = ref({
  userName: '',
  password: '',
  gender: '',
  birthDate: ''
});

const router = useRouter();

const submitForm = async () => {
  if (!userForm.value.userName || !userForm.value.password) {
    ElMessage.error('用户名和密码不能为空');
    return;
  }
    const response = await axios.post('/api/user/add', userForm.value);
      ElMessage.success(response);  // 使用后端返回的消息
      router.push('/');
      ElMessage.error(response);  // 使用后端返回的消息
};

const resetForm = () => {
  Object.assign(userForm.value, {
    userName: '',
    password: '',
    gender: '',
    birthDate: ''
  });
};
</script>

<style s coped>
.full-screen-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: url('../../assets/b2.jpg') no-repeat center center fixed;
  background-size: cover;
}

.form-container {
  width: 360px;
  padding: 40px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0px 15px 25px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.user-form {
  display: flex;
  flex-direction: column;
}

.user-form .el-form-item {
  margin-bottom: 20px;  /* Ensure there is enough space between fields */
}


.el-input,
.el-button {
  margin-bottom: 20px;
}

.el-input {
  width: 100%;          /* Make sure inputs take full width of their container */
  padding: 10px;        /* Adequate padding inside inputs */
  border: 1px solid #ccc; /* Clearly define borders */
  border-radius: 4px;   /* Optionally round corners */
}

.el-input::placeholder {
  color: #aaa;
}

.el-radio-group {
  display: flex;
  justify-content: space-between; /* If you want radio buttons to be spread out */
}


.el-date-picker {
  width: 100%;          /* Ensure date picker takes full width */
}

.el-button {
  background-color: #9c94e2;
  color: #fff;
  transition: background-color 0.3s, transform 0.2s;
  font-size: 15px;
  padding: 10px 15px;  /* Adjust padding and remove fixed width */
}

.el-button:hover {
  background-color: #a0d2da;
  transform: translateY(-2px);
}

.form-actions {
  display: flex;
  justify-content: space-between;
}
</style>






  